﻿using AlarmModule.Enums;
using AlarmModule.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AlarmModule {
    // 报警管理中心（观察者模式核心）
    public class AlarmCenter {
        private readonly List<IAlarmSubscriber> _subscribers = new();

        public void Subscribe(IAlarmSubscriber subscriber) {
            _subscribers.Add(subscriber);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tagName"></param>
        /// <param name="level"></param>
        public void TriggerAlarm(string tagName, AlarmLevel level) {
            foreach (var sub in _subscribers) {
                sub.HandleAlarm(tagName, level);
            }
        }
    }
}
